如何使用moment js将东部标准日期时间转换为Utc? |
您所在的位置:网站首页 › eastern time now › 如何使用moment js将东部标准日期时间转换为Utc? |
您可以使用tz()函数以东部标准时间创建日期。 然后,您可以使用.utc将其转换为utc()。 如果您想要另一个时区(例如巴基斯坦),可以再次使用.tz()来转换: // Our input time (in Eastern Standard Time). const inputTime = '2021-09-03 04:45:00'; // Create our moment object in Eastern Standard Time const easternTime = moment.tz(inputTime, 'EST'); console.log('Times:') console.log('Eastern: ', easternTime.format()); // Now use .utc() to convert to utc timezone. const utcTime = easternTime.utc(); console.log('UTC: ', utcTime.format()); // Now use .tz() to convert to Pakistan Standard Time. const pakistanTime = utcTime.tz('Asia/Karachi'); console.log('Pakistan:', pakistanTime.format()); |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |